package com.home.duy.code.Model;

import java.util.List;
import java.util.Vector;

import javax.swing.event.TableModelEvent;
import javax.swing.event.TableModelListener;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.TableModel;

import org.hibernate.Query;
import org.hibernate.Session;

import com.home.Entity.Ban;
import com.home.System.HibernateUtil;
import com.home.duy.code.DAO.BanDAO;

public class QLBanTableModel extends AbstractTableModel implements
		TableModelListener {
	private static final long serialVersionUID = 1L;
	private String[] column = { "Tên Bàn", "Khu Vực", "Nhân Viên QL",
			"Còn Sử Dụng", "Mô Tả" };

	private int indexPos = 0;
	private int rowCount = 10;

	public QLBanTableModel() {
	}

	public void setIndexRow(int index) {
		indexPos = index;
	}

	@Override
	public int getColumnCount() {
		return column.length;
	}

	public void setRowCount(int rowCount) {
		this.rowCount = rowCount;
	}

	@Override
	public int getRowCount() {
		return this.rowCount;
	}

	@Override
	public Object getValueAt(int rowIndex, int columnIndex) {
		return ((Vector) getData(indexPos).get(rowIndex)).get(columnIndex);
	}

	@Override
	public String getColumnName(int column) {
		// TODO Auto-generated method stub
		return this.column[column];
	}

	@Override
	public Class<?> getColumnClass(int arg0) {
		return getValueAt(0, arg0).getClass();
	}

	@SuppressWarnings({ "rawtypes", "unchecked" })
	private Vector getData(int from) {
		Vector<Object> v = new Vector<Object>();
		BanDAO banDao = new BanDAO();
			List<Ban> re = banDao.findByPaging(getRowCount(), from);
			for (Ban b : re) {
				Vector<Object> col = new Vector<Object>();
				col.add(b.getTen());
				col.add(b.getKhuVucBan().getTen());
				col.add(b.getNhanVien().getTen());
				col.add(b.isSuDung());
				col.add(b.getMoTa());
				col.add(b.getMaSo());

				v.add(col);
			}
		return v;
	}

	@Override
	public void tableChanged(TableModelEvent e) {
	}
}
